﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZP.IBLL;
using ZP.IDAL;
using ZP.Model;

namespace ZP.BLL
{
    public abstract class BaseService<T, TKey> : IBaseService<T, TKey> where T : class, new()
    {
        public IBaseRepository<T, TKey> _repository { get; set; }
        public Ifz_base_employeeDAL _fz_base_employeeDAL { get; set; }//= Container.Resolve<Ifz_base_employeeDAL>();
        public Ifz_sys_userDAL _fz_sys_userDAL { get; set; }//= Container.Resolve<Ifz_sys_userDAL>();
        public Ifz_sys_menuDAL _fz_sys_menuDAL { get; set; }//= Container.Resolve<Ifz_sys_menuDAL>();
        public Ifz_sys_roleDAL _fz_sys_roleDAL { get; set; }//= Container.Resolve<Ifz_sys_roleDAL>();
        public Ifz_base_paramDAL _fz_base_paramDAL { get; set; }

        public Iht_honor_titleDAL _ht_honor_titleDAL { get; set; }
        public Iht_type1_fileDAL _ht_type1_fileDAL { get; set; }
        public Iht_type1_titleDAL _ht_type1_titleDAL { get; set; }
        public Iht_type1_bakDAL _ht_type1_bakDAL { get; set; }

        public Iep_product_infoDAL _ep_product_infoDAL { get; set; }
        public Iep_business_productDAL _ep_business_productDAL { get; set; }
        public Iep_personnel_statsDAL _ep_personnel_statsDAL { get; set; }
        public Iep_basic_dataDAL _ep_basic_dataDAL { get; set; }
        public Iep_ip_infoDAL _ep_ip_infoDAL { get; set; }
        public Iep_cert_qualifiedDAL _ep_cert_qualifiedDAL { get; set; }
        public Iep_htDAL _ep_htDAL { get; set; }
        public Iep_userDAL _ep_userDAL { get; set; }
        public Iep_user_relDAL _ep_user_relDAL { get; set; }

        public Iep_base_infoDAL _ep_base_infoDAL { get; set; }
        public Iep_investorDAL _ep_investorDAL { get; set; }
        public Iep_personnel_infoDAL _ep_personnel_infoDAL { get; set; }
        public Iep_gov_supportDAL _ep_gov_supportDAL { get; set; }

        public BaseService()
        {
            MapperConfig.Initialise();
        }

        public DbContext GetDbContext()
        {
            return _repository.GetDbContext();
        }

        public T Find(TKey id)
        {
            return _repository.Find(id);
        }

        public T Find(Expression<Func<T, bool>> WhereLambda)
        {
            return _repository.Find(WhereLambda);
        }

        public IQueryable<T> GetModels(Expression<Func<T, bool>> whereLambda)
        {
            return _repository.GetModels(whereLambda);
        }

        public IQueryable<T> GetModelsByPage<type>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> WhereLambda, Expression<Func<T, type>> OrderByLambda, bool isAsc)
        {
            return _repository.GetModelsByPage(pageSize, pageIndex, out total, WhereLambda, OrderByLambda, isAsc);
        }

        public bool SaveChanges()
        {
            return _repository.SaveChanges();
        }

        public bool Update(T entity, bool isSaveChage = true)
        {
            return _repository.Update(entity, isSaveChage);
        }

        public void Add(T entity, bool isSaveChage = true)
        {
            _repository.Add(entity, isSaveChage = true);
        }

        public bool Delete(T entity, bool isSaveChage = true)
        {
            return _repository.Delete(entity, isSaveChage);
        }

        public int Delete(params TKey[] ids)
        {
            return _repository.Delete(ids);
        }

        public void Dispose()
        {
            if (_repository != null)
            {
                _repository.Dispose();
            }
        }
    }
}
